package com.example.my_music_palyer.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * 密码配置类
 * 确保BCryptPasswordEncoder正确配置
 */
@Configuration
public class PasswordConfig {
    
    @Bean
    public BCryptPasswordEncoder bCryptPasswordEncoder() {
        // 使用默认的强度设置（10）
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        
        // 测试编码器是否工作正常
        String testPassword = "123456";
        String testHash = encoder.encode(testPassword);
        boolean testResult = encoder.matches(testPassword, testHash);
        
        System.out.println("=== BCryptPasswordEncoder 配置测试 ===");
        System.out.println("测试密码: " + testPassword);
        System.out.println("测试哈希: " + testHash);
        System.out.println("测试结果: " + testResult);
        System.out.println("编码器配置成功: " + (testResult ? "是" : "否"));
        
        return encoder;
    }
}
